/// <summary>
/// method to set a specified printer as the system's default printer
/// </summary>
/// <param name="printerName">name of the printer we want to be default</param>
/// <returns>Returns true if successfull</returns>
/// <exception cref="Exception">Throws exception if printer not installed</exception>
public bool SetPrinterToDefault(string printer)
{
    //path we need for WMI
    string queryPath = "win32_printer.DeviceId='" + printer + "'";

    try
    {
        //ManagementObject for doing the retrieval
        ManagementObject managementObj = new ManagementObject(queryPath);

        //ManagementBaseObject which will hold the results of InvokeMethod
        ManagementBaseObject obj = managementObj.InvokeMethod("SetDefaultPrinter", null, null);

        //if we're null the something went wrong
        if (obj == null)
            throw new Exception("Unable to set default printer.");

        //now get the return value and make our decision based on that
        int result = (int)obj.Properties["ReturnValue"].Value;

        if (result == 0)
            return true;
        else
            return false;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
        return false;
    }
}